//
//  spectral_model_file_dialogue.mm
//  sbrush
//
//  Created by Phillip Popp on 5/8/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "spectral_model_file_dialogue.h"

@implementation SpectralModelFileDialogue

+ (NSArray*) openModal {
	NSOpenPanel *openPanel = [NSOpenPanel openPanel];
	
	/* Configuer open panel */
	[openPanel setTitle:@"Open Spectral Model"];
	[openPanel setCanChooseFiles:YES];
	[openPanel setCanChooseDirectories:NO];
	[openPanel setResolvesAliases:YES];
	[openPanel setAllowsMultipleSelection:YES];
	[openPanel setAllowedFileTypes:[NSArray arrayWithObject:@"sms"]];
	[openPanel setAllowsOtherFileTypes:YES];
	//[openPanel setDirectoryURL:initialPath];
	
	int result = [openPanel runModal];
	
	/* Get the result from whatever user action happened */
	if (result == NSFileHandlingPanelOKButton) {
		NSArray *filesToOpen = [openPanel URLs];
		NSMutableArray* fileItems = nil;
		fileItems = [NSMutableArray arrayWithCapacity:[filesToOpen count]];

		for (NSUInteger i = 0; i < [filesToOpen count]; i++) {
			NSURL *fileUrl = [filesToOpen objectAtIndex:i];
			FileItem* item = [[FileItem alloc] init];
			[item setPath:[fileUrl path]];
			[item setDisplay:[fileUrl lastPathComponent]];
			[fileItems insertObject:item atIndex:i];
		}
		return fileItems;
	}
	else {
		return [NSArray array];
	}
}

@end
